<?php
/**
 * DBShop 电子商务系统
 *
 * ==========================================================================
 * @link      https://www.dbshop.net/
 * @copyright 北京珑大钜商科技有限公司，并保留所有权利。
 * @license   https://www.dbshop.net/license.html License
 * ==========================================================================
 *
 * @author    静静的风 <baron@loongdom.cn>
 *
 */

namespace Sales\Repository\QuerySearch;

use Doctrine\ORM\QueryBuilder;

class OrderRefundLogSearch
{
    public static function querySearchData($search, QueryBuilder $queryBuilder)
    {
        if (isset($search['order_sn']) && !empty($search['order_sn']))                      $queryBuilder->andWhere($queryBuilder->expr()->eq('r.orderSn', ':orderSn'))->setParameter('orderSn', $search['order_sn']);
        if (isset($search['return_type']) && is_numeric($search['return_type']))            $queryBuilder->andWhere($queryBuilder->expr()->eq('r.returnType', ':returnType'))->setParameter('returnType', $search['return_type']);
        if (isset($search['refund_pay_type']) && !empty($search['refund_pay_type']))        $queryBuilder->andWhere($queryBuilder->expr()->eq('r.refundPayType', ':refundPayType'))->setParameter('refundPayType', $search['refund_pay_type']);
        if (isset($search['user_name']) && !empty($search['user_name']))                    $queryBuilder->andWhere($queryBuilder->expr()->eq('r.userName', ':userName'))->setParameter('userName', $search['user_name']);
        if (isset($search['start_finish_time']) && !empty($search['start_finish_time']))    $queryBuilder->andWhere($queryBuilder->expr()->gte('r.finishTime', ':finishTime'))->setParameter('finishTime', strtotime($search['start_finish_time'].' 00:00:00'));
        if (isset($search['end_finish_time']) && !empty($search['end_finish_time']))        $queryBuilder->andWhere($queryBuilder->expr()->lte('r.finishTime', ':finishTime'))->setParameter('finishTime', strtotime($search['end_finish_time'].' 23:59:59'));

        return $queryBuilder;
    }
}